package Java.com.wang.Three;

import org.omg.CORBA.NO_IMPLEMENT;

public class linkQueue <T>{
    private Node<T> front,rear;
    private int length;

    public linkQueue(){
        length=0;
        front=rear=new Node<T>(null);
    }

    public void EnQueue(T obj){
       rear=rear.next=new Node<T>(obj,null);
       length++;
    }

    public T DeQueue(){
        if(isEmpty()){
            System.out.println("队列已空，无法出队");
            return null;
        }
        Node<T> p=front.next;
        T x = p.data;
        front.next=p.next;
        length--;
        if(front.next==null){
            rear=front;
        }
        return x;
    }

    public T GetHead(){
        if(isEmpty()){
            System.out.println("队列已空，无法出队");
            return null;
        }
        return front.next.data;
    }

    public boolean isEmpty() {
        return front .next== rear;
    }

    public int size(){
        return length;
    }

    public void nextOrder(){
        Node<T> p= front.next;
        while(p!=null){
            System.out.println(p.data);
            p=p.next;
        }
    }

    public void clear(){
        front.next=rear.next=null;
    }

}
